#include<stdio.h>
int main()
{
	int m = 0, n = 0;
	while (scanf("%d%d", &m, &n) != EOF)
	{
		int is[m * n], js[m * n], num[m * n];
		int ii = 0;
		int tmp = 0;
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				scanf("%d", &tmp);
				if (tmp % 7 == 0)
				{
					is[ii] = i+1, js[ii] = j+1, num[ii++] = tmp;
				}
			}
		}
		for (int i = 0; i <ii; i++)
		{
			printf("%d %d %d\n", is[i], js[i], num[i]);
		}
	}
	return 0;
}
